package com.davidx.tool.exception;

import cn.hutool.core.exceptions.ExceptionUtil;

import com.davidx.tool.wrapper.WrapMapper;
import com.davidx.tool.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Administrator
 * @date 2018/7/30
 */
@Slf4j
@RestControllerAdvice
public class ErrHandler {


    @ExceptionHandler(Exception.class)
    public Wrapper errAdvice(Exception ex) {
        log.error(ExceptionUtil.getMessage(ex));
        log.error(ExceptionUtil.stacktraceToString(ex));
        return WrapMapper.error();
    }

    @ExceptionHandler(BaseException.class)
    public Wrapper errAdvice(BaseException ex) {
        log.error(ExceptionUtil.getMessage(ex));
        log.error(ExceptionUtil.stacktraceToString(ex));
        return WrapMapper.error(ExceptionUtil.getMessage(ex));
    }
}
